IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'spDOReportReleases_RetrieveAll')
	BEGIN
		PRINT 'Dropping Procedure spDOReportReleases_RetrieveAll'
		DROP  Procedure  spDOReportReleases_RetrieveAll
	END

GO

PRINT 'Creating Procedure spDOReportReleases_RetrieveAll'
GO

CREATE Procedure spDOReportReleases_RetrieveAll
	(
		@d_id varchar(50) = null, 
		@d_folder varchar(50) = null, 
		@d_loc varchar(50) = null, 
		@d_user varchar(50) = null, 
		@d_status varchar(50) = null, 
		@d_match numeric = null, 
		@d_exist numeric = null, 
		@d_releasetype varchar(50) = null, 
		@d_releasereason varchar(500) = null, 
		@d_primaryattorney varchar(100) = null, 
		@d_accno varchar(50) = null, 
		@d_secondaryattorney varchar(100) = null, 
		@d_fileno varchar(50) = null, 
		@d_releasedate DateTime = null, 
		@d_doctype varchar(50) = null, 
		@d_returndate DateTime = null, 
		@d_stand varchar(50) = null, 
		@d_primaryattorneyletterreference varchar(50) = null, 
		@d_secondaryattorneyletterreference varchar(50) = null, 
		@d_suburb varchar(50) = null, 
		@d_customerletterreference varchar(50) = null, 
		@d_complex varchar(50) = null, 
		@d_custid varchar(50) = null, 
		@d_trackingnumber varchar(100) = null, 
		@d_custname1 varchar(100) = null, 
		@d_custname2 varchar(100) = null, 
		@d_lasttran DateTime = null, 
		@d_goldate DateTime = null, 
		@d_mbno varchar(50) = null, 
		@d_tdno varchar(50) = null, 
		@d_hogno varchar(50) = null, 
		@d_onwins varchar(50) = null, 
		@d_owninsno varchar(50) = null, 
		@d_lifecomp varchar(50) = null, 
		@d_lifeno varchar(50) = null, 
		@d_lifecess varchar(50) = null, 
		@d_lifewaiver DateTime = null, 
		@d_govtee varchar(50) = null, 
		@d_letsure DateTime = null, 
		@d_nhbrc numeric = null, 
		@d_authpmt numeric = null, 
		@d_gpadate DateTime = null, 
		@d_addendum varchar(50) = null, 
		@d_notes varchar(8000) = null, 
		@d_releaseNLP numeric = null, 
		@d_notifyreturned numeric = null, 
		@d_releasebatchnumber int = null, 
		@d_releasebatchclosed numeric = null
	)
AS
    /* 
    ------------------------------------------------------------------------------
    - Change History
    - --------------
    - Date          Description
    ------------------------------------------------------------------------------
    - 2007/10/29	Initial version created
    ------------------------------------------------------------------------------
    */
	
	SET NOCOUNT ON
	
	-- Retrieve the relevant records
	SELECT  *
	FROM	DOReportReleases
	
	WHERE	(@d_id IS NULL OR DOReportReleases.d_id LIKE @d_id + '%')
	  AND	(@d_folder IS NULL OR DOReportReleases.d_folder LIKE @d_folder + '%')
	  AND	(@d_loc IS NULL OR DOReportReleases.d_loc LIKE @d_loc + '%')
	  AND	(@d_user IS NULL OR DOReportReleases.d_user LIKE @d_user + '%')
	  AND	(@d_status IS NULL OR DOReportReleases.d_status LIKE @d_status + '%')
	  AND	(@d_match IS NULL OR DOReportReleases.d_match = @d_match)
	  AND	(@d_exist IS NULL OR DOReportReleases.d_exist = @d_exist)
	  AND	(@d_releasetype IS NULL OR DOReportReleases.d_releasetype LIKE @d_releasetype + '%')
	  AND	(@d_releasereason IS NULL OR DOReportReleases.d_releasereason LIKE @d_releasereason + '%')
	  AND	(@d_primaryattorney IS NULL OR DOReportReleases.d_primaryattorney LIKE @d_primaryattorney + '%')
	  AND	(@d_accno IS NULL OR DOReportReleases.d_accno LIKE @d_accno + '%')
	  AND	(@d_secondaryattorney IS NULL OR DOReportReleases.d_secondaryattorney LIKE @d_secondaryattorney + '%')
	  AND	(@d_fileno IS NULL OR DOReportReleases.d_fileno LIKE @d_fileno + '%')
	  AND	(@d_releasedate IS NULL OR DOReportReleases.d_releasedate = @d_releasedate)
	  AND	(@d_doctype IS NULL OR DOReportReleases.d_doctype LIKE @d_doctype + '%')
	  AND	(@d_returndate IS NULL OR DOReportReleases.d_returndate = @d_returndate)
	  AND	(@d_stand IS NULL OR DOReportReleases.d_stand LIKE @d_stand + '%')
	  AND	(@d_primaryattorneyletterreference IS NULL OR DOReportReleases.d_primaryattorneyletterreference LIKE @d_primaryattorneyletterreference + '%')
	  AND	(@d_secondaryattorneyletterreference IS NULL OR DOReportReleases.d_secondaryattorneyletterreference LIKE @d_secondaryattorneyletterreference + '%')
	  AND	(@d_suburb IS NULL OR DOReportReleases.d_suburb LIKE @d_suburb + '%')
	  AND	(@d_customerletterreference IS NULL OR DOReportReleases.d_customerletterreference LIKE @d_customerletterreference + '%')
	  AND	(@d_complex IS NULL OR DOReportReleases.d_complex LIKE @d_complex + '%')
	  AND	(@d_custid IS NULL OR DOReportReleases.d_custid LIKE @d_custid + '%')
	  AND	(@d_trackingnumber IS NULL OR DOReportReleases.d_trackingnumber LIKE @d_trackingnumber + '%')
	  AND	(@d_custname1 IS NULL OR DOReportReleases.d_custname1 LIKE @d_custname1 + '%')
	  AND	(@d_custname2 IS NULL OR DOReportReleases.d_custname2 LIKE @d_custname2 + '%')
	  AND	(@d_lasttran IS NULL OR DOReportReleases.d_lasttran = @d_lasttran)
	  AND	(@d_goldate IS NULL OR DOReportReleases.d_goldate = @d_goldate)
	  AND	(@d_mbno IS NULL OR DOReportReleases.d_mbno LIKE @d_mbno + '%')
	  AND	(@d_tdno IS NULL OR DOReportReleases.d_tdno LIKE @d_tdno + '%')
	  AND	(@d_hogno IS NULL OR DOReportReleases.d_hogno LIKE @d_hogno + '%')
	  AND	(@d_onwins IS NULL OR DOReportReleases.d_onwins LIKE @d_onwins + '%')
	  AND	(@d_owninsno IS NULL OR DOReportReleases.d_owninsno LIKE @d_owninsno + '%')
	  AND	(@d_lifecomp IS NULL OR DOReportReleases.d_lifecomp LIKE @d_lifecomp + '%')
	  AND	(@d_lifeno IS NULL OR DOReportReleases.d_lifeno LIKE @d_lifeno + '%')
	  AND	(@d_lifecess IS NULL OR DOReportReleases.d_lifecess LIKE @d_lifecess + '%')
	  AND	(@d_lifewaiver IS NULL OR DOReportReleases.d_lifewaiver = @d_lifewaiver)
	  AND	(@d_govtee IS NULL OR DOReportReleases.d_govtee LIKE @d_govtee + '%')
	  AND	(@d_letsure IS NULL OR DOReportReleases.d_letsure = @d_letsure)
	  AND	(@d_nhbrc IS NULL OR DOReportReleases.d_nhbrc = @d_nhbrc)
	  AND	(@d_authpmt IS NULL OR DOReportReleases.d_authpmt = @d_authpmt)
	  AND	(@d_gpadate IS NULL OR DOReportReleases.d_gpadate = @d_gpadate)
	  AND	(@d_addendum IS NULL OR DOReportReleases.d_addendum LIKE @d_addendum + '%')
	  AND	(@d_notes IS NULL OR DOReportReleases.d_notes LIKE @d_notes + '%')
	  AND	(@d_releaseNLP IS NULL OR DOReportReleases.d_releaseNLP = @d_releaseNLP)
	  AND	(@d_notifyreturned IS NULL OR DOReportReleases.d_notifyreturned = @d_notifyreturned)
	  AND	(@d_releasebatchnumber IS NULL OR DOReportReleases.d_releasebatchnumber = @d_releasebatchnumber)
	  AND	(@d_releasebatchclosed IS NULL OR DOReportReleases.d_releasebatchclosed = @d_releasebatchclosed)

	-- Return to calling method
	RETURN
GO
